import post from "@/api/base.js";

export const indexUrl = process.env.VUE_APP_RESOURCE_URL

//保存用户信息
export const setUserInfo = (user) => {
    if (user.id) window.localStorage.setItem("uid", user.id);
    if (user.username) window.localStorage.setItem("username", user.username);
    if (user.header) window.localStorage.setItem("header", user.header);
    if (user.token) window.localStorage.setItem("token", user.token);
    if (user.school_id) window.localStorage.setItem("school_id", user.school_id);
}
//获取用户信息
export const getUserInfo = () => {
    return {
        uid: window.localStorage.uid,
        username: window.localStorage.username,
        header: window.localStorage.header,
        token: window.localStorage.token,
        school_id: window.localStorage.school_id,
    };
}
//清空用户信息
export const clearUserInfo = () => {
    window.localStorage.removeItem("uid");
    window.localStorage.removeItem("username");
    window.localStorage.removeItem("header");
    window.localStorage.removeItem("token");
    window.localStorage.removeItem("school_id");
}

export const upload = formData => post(`${indexUrl}/util/upload`, formData)

export const indexDataReq = formData => post('index/data', formData)

export const indexDotReq = formData => post('index/dot', formData)

export const areaListReq = () => post('area/list')

export const deliverListReq = data => post('deliver/list', data)

export const getSchoolId = () => {
    let school_id = window.localStorage.school_id
    if (!school_id) {
        school_id = null
    }
    return school_id
}